const innerAudioContext = wx.createInnerAudioContext();
const app = getApp();

Component({
  data: {
    mp3: 'https://yijing.wcip.net/upload/audio/jk.mp3',
    bgm: false
  },
  ready() {
    this.init();
  },
  methods: {
    init() {
      innerAudioContext.autoplay = true;
      innerAudioContext.loop = true;
      innerAudioContext.src = this.data.mp3;
      innerAudioContext.volume = 0.3;
      innerAudioContext.play();
      this.setData({ bgm: true });
    },
    bgm() {
      if (this.data.bgm) {
        this.setData({ bgm: false });
        innerAudioContext.pause();
      } else {
        this.setData({ bgm: true });
        innerAudioContext.play();
      }
    }
  }
});